# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=pyrsistent
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-${_realname}"  "${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=0.15.5
pkgrel=1
pkgdesc="Persistent/Functional/Immutable data structures (mingw-w64)"
arch=('any')
url='https://github.com/tobgu/pyrsistent'
license=('MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-python2"
             "${MINGW_PACKAGE_PREFIX}-python3"
             "${MINGW_PACKAGE_PREFIX}-python3-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python2-setuptools")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python3-pytest-runner"
              "${MINGW_PACKAGE_PREFIX}-python2-pytest-runner"
              "${MINGW_PACKAGE_PREFIX}-python3-flake8"
              "${MINGW_PACKAGE_PREFIX}-python2-flake8"
              "${MINGW_PACKAGE_PREFIX}-python3-hypothesis"
              "${MINGW_PACKAGE_PREFIX}-python2-hypothesis")
options=('staticlibs' 'strip' '!debug')
source=("https://pypi.io/packages/source/p/pyrsistent/pyrsistent-${pkgver}.tar.gz"
        LICENCE.mit)
sha512sums=('6cdf561be95d6379138c5b7c09c47eb2fa52571e4bfefb2c09ebb302d15f04e2aca88f26fe24977de48ac27eff76f0731a12ac5d669f0d4cdcf44a997969dafa'
            '036bd5cc2a62b004576ecc50a84dc7d187d8108f52cb886f7e32bed324327af2dc132100e1c8f1dd2ce35b774f74898020f04a315e5137319deda18a449e791a')

prepare() {
  cd "${srcdir}"
  for builddir in python{2,3}-build-${CARCH}; do
    rm -rf ${builddir} | true
    cp -r "${_realname}-${pkgver}" "${builddir}"
  done
  # Set version for setuptools_scm
  export SETUPTOOLS_SCM_PRETEND_VERSION=$pkgver
}

build() {
  for pver in {2,3}; do
    msg "Python ${pver} build for ${CARCH}"
    cd "${srcdir}/python${pver}-build-${CARCH}"
    ${MINGW_PREFIX}/bin/python${pver} setup.py build
  done
}

check() {
  for pver in {2,3}; do
    msg "Python ${pver} test for ${CARCH}"
    cd "${srcdir}/python${pver}-build-${CARCH}"
    ${MINGW_PREFIX}/bin/python${pver} setup.py pytest || warning "tests failed!!"
  done
}

package_python3-pyrsistent() {
  depends=("${MINGW_PACKAGE_PREFIX}-python3"
           "${MINGW_PACKAGE_PREFIX}-python3-six")

  cd "${srcdir}/python3-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python3 setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 LICENCE.mit "${pkgdir}${MINGW_PREFIX}/share/licenses/python3-${_realname}/LICENCE.mit"
}

package_python2-pyrsistent() {
  depends=("${MINGW_PACKAGE_PREFIX}-python2"
           "${MINGW_PACKAGE_PREFIX}-python2-six")

  cd "${srcdir}/python2-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 LICENCE.mit "${pkgdir}${MINGW_PREFIX}/share/licenses/python2-${_realname}/LICENCE.mit"
}

package_mingw-w64-i686-python2-pyrsistent() {
  package_python2-pyrsistent
}

package_mingw-w64-i686-python3-pyrsistent() {
  package_python3-pyrsistent
}

package_mingw-w64-x86_64-python2-pyrsistent() {
  package_python2-pyrsistent
}

package_mingw-w64-x86_64-python3-pyrsistent() {
  package_python3-pyrsistent
}
